home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Programmation / Gooey1.3.1 / C++ Templates / mmWindow.c < prev    next >
Text File  |  1994-06-08  |  38KB  |  1,081 lines

  1. $$Loop Windows
  2. $$Message MM Window, mm:mmW_$Worksheet.name$.cp
  3.  
  4. $$File mm:mmW_$Worksheet.name$.cp
  5. /*  mmW_$Worksheet.name$                                 Handle this Window */
  6. /*  $CopyRight$ */
  7.  
  8. /* 
  9.     File name: mmW_$Worksheet.name$
  10.     Function: Handle a Window 
  11.     History: $Date$ Original by $Author$
  12.  
  13. */
  14.  
  15. #include "mmCommon$Prototype.name$.h"    /* Common */
  16. #include "Common$Prototype.name$.h"        /* Common */
  17.  
  18.  
  19. /* ======================================================= */
  20. $$if Worksheet.Scrollbars
  21. /* ======================================================= */
  22.  
  23. /* Routine: HandleScrollBar */
  24. /* Purpose: Handle a ScrollBar being pressed */
  25.  
  26. void CmmW$Worksheet.name$::HandleScrollBar(short code,ControlHandle theControl,Point myPt)
  27. {
  28. long    RefCon;                                    /* RefCon for controls */
  29.  
  30.  
  31. RefCon = GetCRefCon(theControl);                /* get control refcon */
  32.  
  33. switch (RefCon)                                    /* Select correct scrollbar */
  34.     {
  35.     $$Loop Control.type = ScrollBar
  36.     case ResC_$Control.name$:                    /* Scroll bar, $Control.FullName$  */
  37.         HandleWScrollBar(myPt,code,$Control.StepScroll$,$Control.PageScroll$,theControl);/*  code,Inc,PageInc,handle  */
  38.         break;
  39.  
  40.     $$EndLoop
  41.     $$Loop Control.type = UGauge
  42.     case ResC_$Control.name$:                    /* Plugin gauge, $Control.FullName$  */
  43.         HandleWScrollBar(myPt,code,$Control.StepScroll$,$Control.PageScroll$,theControl);/*  code,Inc,PageInc,handle  */
  44.         break;
  45.  
  46.     $$EndLoop
  47. $$if Worksheet.Document
  48. $$if Worksheet.ScrollHorz
  49.     case 12345L:
  50.         HandleWScrollBar(myPt,code,1,10,theControl);
  51.         break;
  52.  
  53. $$endif
  54. $$if Worksheet.ScrollVert
  55.     case 12346L:
  56.         HandleWScrollBar(myPt,code,1,10,theControl);
  57.         break;
  58.  
  59. $$endif
  60. $$endif Worksheet.Document
  61.     default:                                    /* allow other buttons, trap for debug */
  62.         break;                                    /* end of otherwise */
  63.     }                                            /* end of switch */
  64. }
  65.  
  66. $$endif
  67. /* ======================================================= */
  68. /* ======================================================= */
  69.  
  70. void CmmW$Worksheet.name$::InitRecord($Worksheet.name$PRec theWS)
  71. {
  72.  
  73.  
  74. theWS->theWindow = nil;                    /* Make sure other routines know we are not valid yet */
  75. theWS->ExtrasHdl = nil;                    /* Not used by MM code, dedicated to user code */
  76.  
  77. $$if Worksheet.Document
  78. $$if Worksheet.ScrollHorz
  79. theWS->ScrollHHandle = nil;                /* Scrollbar is not valid yet */
  80. theWS->ScrollHLeftOffset = -1;            /* Offset of control from left side */
  81. $$endif
  82. $$if Worksheet.ScrollVert
  83. theWS->ScrollVHandle = nil;                /* Scrollbar is not valid yet */
  84. theWS->ScrollVTopOffset = -1;            /* Offset of control from top edge */
  85. $$endif
  86. $$endif Worksheet.Document
  87. /* Set the window back color */
  88. theWS->WindowBackColor.red  = 0x$Worksheet.RedBackColor$;  
  89. theWS->WindowBackColor.green  = 0x$Worksheet.GreenBackColor$;  
  90. theWS->WindowBackColor.blue  = 0x$Worksheet.BlueBackColor$;
  91.  
  92. $$Loop Control.type = Button
  93. theWS->Enable_$Control.name$ = $Control.Active$;                /* Button, $Control.FullName$  */
  94. $$EndLoop
  95. $$Loop Control.type = HotRect
  96. $$if Control.HotSpot
  97. theWS->Enable_$Control.name$ = $Control.Active$;                /* HotSpot, $Control.FullName$  */
  98. $$endif
  99. $$EndLoop
  100. $$Loop Control.type = Checkbox
  101. theWS->Enable_$Control.name$ = $Control.Active$;                /* Checkbox, $Control.FullName$  */
  102. $$if Control.Selected
  103. theWS->Value_$Control.name$ = 1;
  104. $$endif
  105. $$if Control.Unselected
  106. theWS->Value_$Control.name$ = 0;
  107. $$endif
  108. $$EndLoop
  109. $$Loop Control.type = Radio
  110. theWS->Enable_$Control.name$ = $Control.Active$;                /* Radio, $Control.FullName$  */
  111. $$if Control.Selected
  112. theWS->Value_$Control.name$ = 1;
  113. $$endif
  114. $$if Control.Unselected
  115. theWS->Value_$Control.name$ = 0;
  116. $$endif
  117. $$EndLoop
  118. $$Loop Control.type = ScrollBar
  119. theWS->Enable_$Control.name$ = $Control.Active$;                /* ScrollBar, $Control.FullName$  */
  120. theWS->Value_$Control.name$ = $Control.ValueScroll$;
  121. $$EndLoop
  122. $$Loop Control.type = Icon
  123. $$if Control.NonGraphic
  124. theWS->Enable_$Control.name$ = $Control.Active$;                /* Icon button, $Control.FullName$  */
  125. $$endif
  126. $$EndLoop
  127. $$Loop Control.type = Sicn
  128. $$if Control.NonGraphic
  129. theWS->Enable_$Control.name$ = $Control.Active$;                /* Sicn button, $Control.FullName$  */
  130. $$endif
  131. $$EndLoop
  132. $$Loop Control.type = Picture
  133. $$if Control.NonGraphic
  134. theWS->Enable_$Control.name$ = $Control.Active$;                /* Picture button, $Control.FullName$  */
  135. $$endif
  136. $$EndLoop
  137. $$Loop Control.type = UButton
  138. theWS->Enable_$Control.name$ = $Control.Active$;                /* Plugin button, $Control.FullName$  */
  139. $$EndLoop
  140. $$Loop Control.type = UToggle
  141. theWS->Enable_$Control.name$ = $Control.Active$;                /* Plugin toggle, $Control.FullName$  */
  142. $$if Control.Selected
  143. theWS->Value_$Control.name$ = 1;
  144. $$endif
  145. $$if Control.Unselected
  146. theWS->Value_$Control.name$ = 0;
  147. $$endif
  148. $$EndLoop
  149. $$Loop Control.type = UGauge
  150. theWS->Enable_$Control.name$ = $Control.Active$;                /* Plugin gauge, $Control.FullName$  */
  151. theWS->Value_$Control.name$ = $Control.ValueScroll$;
  152. $$EndLoop
  153. $$Loop Control.type = Popup
  154. theWS->Enable_$Control.name$ = $Control.Active$;                /* Popup menu, $Control.FullName$  */
  155. theWS->Value_$Control.name$ = $Control.SelectedID$;
  156. $$EndLoop
  157. $$Loop Control.type = Palette
  158. theWS->Enable_$Control.name$ = $Control.Active$;                /* Palette, $Control.FullName$  */
  159. theWS->Value_$Control.name$ = $Control.ValueScroll$;
  160. $$EndLoop
  161. $$Loop Control.type = List
  162. theWS->List_$Control.name$ = nil;                                /* List, $Control.FullName$ */
  163. SetRect(&theWS->ListRect_$Control.name$,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);                /* left,top,right,bottom */
  164. $$EndLoop
  165. $$Loop Control.type = EditText
  166. theWS->TE_$Control.name$ = nil;                                /* Edit Text, $Control.FullName$ */
  167. SetRect(&theWS->TERect_$Control.name$,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);                /* left,top,right,bottom */
  168. GetIndString(theWS->TEStr_$Control.name$,sResC_$Control.name$,1);/*  ...Edit text, default value  */
  169. $$EndLoop
  170. }
  171.  
  172. /* ======================================================= */
  173.  
  174. void CmmW$Worksheet.name$::LocateInstance(WindowPtr theWindow)
  175. {
  176. $Worksheet.name$PRec        ckWS,theWS;
  177.  
  178.  
  179. theWS = nil;                            /* Init to not found */
  180. ckWS = this->ListRecPtr;
  181. while (ckWS != nil)
  182.     {
  183.     if (ckWS->theWindow == theWindow)
  184.         theWS = ckWS;
  185.     ckWS = ckWS->Next;
  186.     }
  187. this->RecPtr = theWS;
  188. }
  189.  
  190. /* ======================================================= */
  191.  
  192. /* Routine: Init */
  193. /* Purpose: Initialize our window data to not in use yet */
  194.  
  195. void CmmW$Worksheet.name$::Init()
  196. {
  197.  
  198. inherited::Init();
  199.  
  200. $$if Worksheet.SavePosition
  201. theWindowLocRec.Loc_$Worksheet.name$.left = $Worksheet.LeftPosition$;            /* Set default Horz position */
  202. theWindowLocRec.Loc_$Worksheet.name$.top = $Worksheet.TopPosition$;            /* Set default Vert position */
  203. theWindowLocRec.Loc_$Worksheet.name$.right = theWindowLocRec.Loc_$Worksheet.name$.left;
  204. theWindowLocRec.Loc_$Worksheet.name$.bottom = theWindowLocRec.Loc_$Worksheet.name$.top;
  205.  
  206. $$endif Worksheet.SavePosition
  207. this->RecPtr = nil;                                        /* No open windows yet */
  208. this->ListRecPtr = nil;
  209. }
  210.  
  211. /* ======================================================= */
  212.  
  213. /* Routine: Close */
  214. /* Purpose: Close out the window */
  215.  
  216. void CmmW$Worksheet.name$::Close(WindowPtr whichWindow)
  217. {
  218. $Worksheet.name$PRec        ckWS,theWS;
  219. $$if Worksheet.SavePosition
  220. Point                theFinalPosition;
  221. Rect                temp2Rect;
  222. $$endif Worksheet.SavePosition
  223.  
  224.  
  225. if (whichWindow == (WindowPtr)-1)
  226.     whichWindow = FrontWindow();
  227.     
  228. this->LocateInstance(whichWindow);
  229.  
  230. /* See if we should close this window */
  231. if (this->RecPtr != nil)
  232.     {
  233.     theWS = this->RecPtr;
  234.     
  235.     this->CloseExtras((Ptr)theWS);                    /* HOOK for user */
  236.  
  237.     $$Loop Control.type = EditText
  238.     if (theInput == theWS->TE_$Control.name$)        /* See if this Text Edit field handle */
  239.         theInput = nil;                                /* Clear the handle used */
  240.     $$if Control.Global
  241.     Get_TE_String(theWS->TE_$Control.name$,(Str255 *)&theWS->TEStr_$Control.name$);
  242.     $$endif Control.Global
  243.     TEDispose(theWS->TE_$Control.name$);            /* Dispose of a List, $Control.FullName$ */
  244.  
  245.     $$EndLoop
  246.     $$Loop Control.type = List
  247.     LDispose(theWS->List_$Control.name$);            /* Dispose of a List, $Control.FullName$ */
  248.  
  249.     $$EndLoop
  250.     $$if Worksheet.SavePosition
  251.     SetPort(whichWindow);                            /* Select our window */
  252.     theFinalPosition.h = 0;
  253.     theFinalPosition.v = 0;
  254.     LocalToGlobal(&theFinalPosition);    /* Get global location */
  255.     theWindowLocRec.Loc_$Worksheet.name$.left = theFinalPosition.h;
  256.     theWindowLocRec.Loc_$Worksheet.name$.top = theFinalPosition.v;
  257.     temp2Rect = theWS->theWindow->portRect;    /* Get the window rectangle */
  258.     theWindowLocRec.Loc_$Worksheet.name$.right = theWindowLocRec.Loc_$Worksheet.name$.left
  259.         + (temp2Rect.right - temp2Rect.left);
  260.     theWindowLocRec.Loc_$Worksheet.name$.bottom = theWindowLocRec.Loc_$Worksheet.name$.top
  261.         + (temp2Rect.bottom - temp2Rect.top);
  262.  
  263.     $$endif Worksheet.SavePosition
  264.     Mk_CloseLayeredWindow(whichWindow);                /* Notify the layer code that we are closing */
  265.  
  266.     DisposeWindow(whichWindow);                        /* Clear window and controls */
  267.  
  268.     ckWS = this->ListRecPtr;
  269.     if (ckWS == theWS)                                /* See if first in the list */
  270.         {
  271.         this->ListRecPtr = theWS->Next;                /* Use second one as new first */
  272.         DisposePtr((Ptr)theWS);                        /* Get rid of this one */
  273.         }
  274.     else
  275.         {
  276.         while (ckWS != nil)                            /* Loop thru them all */
  277.             {
  278.             if (ckWS->Next == theWS)                /* See if the next one is a match */
  279.                 {
  280.                 ckWS->Next = theWS->Next;            /* Get new next one */
  281.                 DisposePtr((Ptr)theWS);                /* Get rid of this one */
  282.                 ckWS = nil;                            /* Get us out of the loop */
  283.                 }
  284.             else
  285.                 ckWS = ckWS->Next;                    /* Try the next one */
  286.             }
  287.         }
  288.  
  289.     this->RecPtr = nil;                                /* No active one */
  290.  
  291.     $$Link    Worksheet.Close
  292.     }
  293. }
  294.  
  295. /* ======================================================= */
  296.  
  297. /* Routine: Resized */
  298. /* Purpose: We were resized or zoomed, update the scrolling scrollbars */
  299.  
  300. void CmmW$Worksheet.name$::Resized(Rect *OldRect,WindowPtr whichWindow)
  301. {
  302. WindowPtr    SavePort;                                /* Place to save the last port */
  303. Rect        temp2Rect;                                /* temp rectangle */
  304. short        Index;                                    /* temp integer */
  305. ControlHandle    ScrollHandle;
  306. $Worksheet.name$PRec        theWS;
  307.  
  308.  
  309. LocateInstance(whichWindow);
  310.  
  311. if (this->RecPtr != nil)                            /* Only do if the window is us */
  312.     {
  313.     theWS = this->RecPtr;
  314.     
  315.     GetPort(&SavePort);                                /* Save the current port */
  316.     SetPort(whichWindow);                            /* Set the port to my window */
  317.  
  318.     $$if Worksheet.Document
  319.     temp2Rect = theWS->theWindow->portRect;    /* Get the window rectangle */
  320.     EraseRect(&temp2Rect);                            /* Erase the new window area */
  321.     InvalRect(&temp2Rect);                            /* Set to update the new window area */
  322.  
  323. $$if Worksheet.ScrollHorz
  324.     if (theWS->ScrollHHandle != nil)                /* Only do if the control is valid */
  325.         {
  326.         ScrollHandle = theWS->ScrollHHandle;
  327.         HLock((Handle)ScrollHandle);                /* Lock the handle while we use it */
  328.         tempRect = (*ScrollHandle)->contrlRect;        /* Get the last control position */
  329.         tempRect.top = tempRect.top - 4;            /* Widen the area to update */
  330.         tempRect.right = tempRect.right + 16;        /* Widen the area to update */
  331.         InvalRect(&tempRect);                        /* Flag old position for update routine */
  332.         tempRect = (*ScrollHandle)->contrlRect;        /* Get the last control position */
  333.         temp2Rect = whichWindow->portRect;            /*  Get the window rectangle */
  334.         Index = temp2Rect.right - temp2Rect.left - 13;/* Get the scroll area width */
  335.         tempRect.left = theWS->ScrollHLeftOffset;    
  336.         HideControl(ScrollHandle);                    /* Hide it during size and move */
  337.         SizeControl(ScrollHandle, Index,16);        /* Make it 16 pixels high, std width */
  338.         MoveControl(ScrollHandle,tempRect.left,temp2Rect.bottom - temp2Rect.top-15);/* Size it correctly */
  339.         ShowControl(ScrollHandle);                    /* Safe to show it now */
  340.         HUnlock((Handle)ScrollHandle);                /* Let it float again */
  341.         }
  342.  
  343. $$endif
  344. $$if Worksheet.ScrollVert
  345.     if (theWS->ScrollVHandle != nil)                /* Only do if the control is valid */
  346.         {
  347.         ScrollHandle = theWS->ScrollVHandle;
  348.         HLock((Handle)ScrollHandle);                /* Lock the handle while we use it */
  349.         tempRect = (*ScrollHandle)->contrlRect;        /* Get the last control position */
  350.         tempRect.left = tempRect.left - 4;            /* Widen the area to update */
  351.         tempRect.bottom = tempRect.bottom + 16;        /* Widen the area to update */
  352.         InvalRect(&tempRect);                        /* Flag old position for update routine */
  353.         tempRect = (*ScrollHandle)->contrlRect;        /* Get the last control position */
  354.         temp2Rect = whichWindow->portRect;            /*  Get the window rectangle */
  355.         Index = temp2Rect.bottom - temp2Rect.top - 13;/* Get the scroll area height */
  356.         tempRect.top = theWS->ScrollVTopOffset;
  357.         HideControl(ScrollHandle);                    /* Hide it during size and move */
  358.         SizeControl(ScrollHandle,16,Index);            /* Make it 16 pixels high, std height */
  359.         MoveControl(ScrollHandle,temp2Rect.right - temp2Rect.left-15,tempRect.top);/* Size it correctly */
  360.         ShowControl(ScrollHandle);                    /* Safe to show it now */
  361.         HUnlock((Handle)ScrollHandle);                /* Let it float again */
  362.         }
  363.  
  364. $$endif
  365.     $$endif Worksheet.Document
  366.  
  367.     this->Moved(OldRect,whichWindow);                /* The window was zoomed or resized */
  368.  
  369.     SetPort(SavePort);                                /* Restore the old port */
  370.     }
  371. }
  372.  
  373. /* ======================================================= */
  374.  
  375. /* Routine: Update */
  376. /* Purpose: Update our window */
  377.  
  378. void CmmW$Worksheet.name$::Update(WindowPtr whichWindow)
  379. {
  380. WindowPtr    SavePort;                            /* Place to save the last port */
  381. $$if Worksheet.Icons
  382. Handle        Icon_Handle;                        /* Handle used in displaying icons */
  383. $$endif Worksheet.Icons
  384. $$if Worksheet.Pictures
  385. PicHandle    Pic_Handle;                            /* Handle used in displaying pictures */
  386. $$endif Worksheet.Pictures
  387. RGBColor    Saved_ForeColor;                    /* Place to save colors */
  388. RGBColor    Saved_BackColor;                    /* Place to save colors */
  389. RGBColor    DrawingColor;                        /* Place to make colors */
  390. $Worksheet.name$PRec        theWS;
  391.  
  392.  
  393. LocateInstance(whichWindow);
  394.  
  395. if (this->RecPtr != nil)                        /* Only do if the window is us */
  396.     {
  397.     theWS = this->RecPtr;
  398.  
  399.     GetPort(&SavePort);                            /* Save the current port */
  400.     SetPort(whichWindow);                        /* Set the port to my window */
  401.  
  402.     $$if Worksheet.HasControls
  403.     if (Has.ColorQD)                                /* See if color QuickDraw is around */
  404.         {
  405.         GetForeColor(&Saved_ForeColor);            /* Save the fore color */
  406.         GetBackColor(&Saved_BackColor);            /* Save the back color */
  407.  
  408.         RGBForeColor(&Black_ForeColor);            /* Set the fore color to Black */
  409.         RGBBackColor(&White_BackColor);            /* Set the back color to White */
  410.         }                                        /* End of IF */
  411.  
  412.     $$Set TextSize = 12
  413.     $$Set TextFont = applFont
  414.     $$Set TextStyle = 0
  415. $$Loop Control.type = StaticText
  416.     /* Draw static text, $Control.FullName$ */
  417.     $$if Control.TextColor ! Black
  418.     if (Has.ColorQD)                                        /* See if color QuickDraw is around */
  419.         {
  420.         DrawingColor.red = 0x$Control.RedTextColor$;
  421.         DrawingColor.green = 0x$Control.GreenTextColor$;
  422.         DrawingColor.blue = 0x$Control.BlueTextColor$;
  423.         RGBForeColor(&DrawingColor);                    /* Set the fore color */
  424.         RGBBackColor(&Saved_BackColor);                    /* Set the back color */
  425.         }
  426.     $$endif Control.TextColor
  427.     $$if Control.MultipleLine
  428.     SetRect(&tempRect,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);
  429.     DrawStaticTextBox(sResC_$Control.name$,&tempRect,$Control.TextAlignment$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$);
  430.     $$endif Control.MultipleLine
  431.     $$if Control.SingleLine
  432.     DrawStaticLine(sResC_$Control.name$,$Control.LeftPosition$,$Control.TopPosition$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$);
  433.     $$endif Control.SingleLine
  434.     $$if Control.TextColor ! Black
  435.     if (Has.ColorQD)                                    /* See if color QuickDraw is around */
  436.         {
  437.         RGBForeColor(&Black_ForeColor);                    /* Set the fore color */
  438.         RGBBackColor(&White_BackColor);                    /* Set the back color */
  439.         }
  440.     $$endif Control.TextColor
  441.  
  442. $$EndLoop
  443. $$Loop Control.type = Icon
  444.     $$if Control.Graphic
  445.     /* Draw an Icon */
  446.     Icon_Handle = GetIcon(ResC_N_$Control.name$);        /* Get Icon into memory */
  447.     SetRect(&tempRect,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);
  448.     if (Icon_Handle != nil)                                /* Only use handle if it is valid */
  449.         PlotIcon(&tempRect,Icon_Handle);                /* Draw the icon in the window */
  450.  
  451.     $$endif Control.Graphic
  452. $$EndLoop
  453. $$Loop Control.type = Sicn
  454.     $$if Control.Graphic
  455.     /* Draw an sicn */
  456.     SetRect(&tempRect,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);
  457.     Plot_Sicn(ResC_N_$Control.name$, &tempRect);        /* Draw the sicn */
  458.  
  459.     $$endif Control.Graphic
  460. $$EndLoop
  461. $$Loop Control.type = Picture
  462.     $$if Control.Graphic
  463.     /* Draw the Picture */
  464.     Pic_Handle = GetPicture(ResC_N_$Control.name$);    /* Get Picture into memory */
  465.     SetRect(&tempRect,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);
  466.     $$if Control.ClipPicture
  467.     if (Pic_Handle != nil)                            /* Only use handle if it is valid */
  468.         {
  469.         ClipRect(&tempRect);                        /* Clip picture to this rectangle */
  470.         HLock((Handle)Pic_Handle);                    /* Lock the handle before using it */
  471.         tempRect.right = tempRect.left + ((*Pic_Handle)->picFrame.right - (*Pic_Handle)->picFrame.left);
  472.         tempRect.bottom = tempRect.top + ((*Pic_Handle)->picFrame.bottom - (*Pic_Handle)->picFrame.top);
  473.         HUnlock((Handle)Pic_Handle);                /* Unlock the picture again */
  474.         }
  475.     $$endif Control.ClipPicture
  476.     if (Pic_Handle != nil)                            /* Only use handle if it is valid */
  477.         DrawPicture(Pic_Handle, &tempRect);            /* Draw this picture */
  478.     $$if Control.ClipPicture
  479.     SetRect(&tempRect, 0, 0, 32000, 32000);            /* Widen the clip area again */
  480.     ClipRect(&tempRect);                            /* Set the clip area */
  481.     $$endif Control.ClipPicture
  482.     $$endif Control.Graphic
  483.  
  484. $$EndLoop
  485. $$Loop Control.type = EditText
  486.     /* Draw Edit text */
  487.     $$if Control.TextColor ! Black
  488.     if (Has.ColorQD)                                        /* See if color QuickDraw is around */
  489.         {
  490.         DrawingColor.red = 0x$Control.RedTextColor$;
  491.         DrawingColor.green = 0x$Control.GreenTextColor$;
  492.         DrawingColor.blue = 0x$Control.BlueTextColor$;
  493.         RGBForeColor(&DrawingColor);                    /* Set the fore color */
  494.         RGBBackColor(&Saved_BackColor);                    /* Set the back color */
  495.         }
  496.     $$endif Control.TextColor
  497.     DrawTheTEArea(&theWS->TERect_$Control.name$,theWS->TE_$Control.name$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$);
  498.     $$if Control.TextColor ! Black
  499.     if (Has.ColorQD)                                        /* See if color QuickDraw is around */
  500.         {
  501.         RGBForeColor(&Black_ForeColor);                    /* Set the fore color */
  502.         RGBBackColor(&White_BackColor);                    /* Set the back color */
  503.         }
  504.     $$endif Control.TextColor
  505.     
  506. $$EndLoop
  507. $$Loop Control.type = Line
  508.     /* Draw a line, $Control.FullName$ */
  509.     $$if Control.GrayLine
  510.     PenPat(qd.gray);                                        /* Set the gray pen pattern */
  511.     $$endif Control.GrayLine
  512.     $$if Control.LineWidth ! 1
  513.     PenSize($Control.LineWidth$,$Control.LineWidth$);
  514.     $$endif Control.LineWidth
  515.     MoveTo($Control.LeftPosition$,$Control.TopPosition$);        /* Horz,vert, Move to starting position */
  516.     LineTo($Control.RightPosition$,$Control.BottomPosition$);    /* Horz,vert, Draw to the ending position */
  517.     $$if Control.LineWidth ! 1
  518.     PenSize(1,1);
  519.     $$endif Control.LineWidth
  520.     $$if Control.GrayLine
  521.     PenPat(qd.black);                                        /*  Back to default pen pattern  */
  522.     $$endif Control.GrayLine
  523.  
  524. $$EndLoop
  525. $$Loop Control.type = List
  526.     /* Update a List */
  527.     UpdateTheList(theWS->theWindow->visRgn,theWS->List_$Control.name$,&theWS->ListRect_$Control.name$,
  528.         $Control.TextSize$,$Control.TextFont$,$Control.TextStyle$,false);
  529.  
  530. $$EndLoop
  531.  
  532.     if (Has.ColorQD)                                /* See if color QuickDraw is around */
  533.         {
  534.         RGBForeColor(&Saved_ForeColor);            /* Restore the fore color */
  535.         RGBBackColor(&Saved_BackColor);            /* Restore the back color */
  536.         }                                        /* End of IF */
  537.  
  538.     $$endif Worksheet.HasControls
  539.  
  540.     TextFont(applFont);                            /* Back to the application font */
  541.     TextSize(12);                                /* Back to the application size */
  542.     TextFace(0);                                /* Set text style */
  543.  
  544.     this->UpdateExtras((Ptr)theWS);                /* HOOK */
  545.  
  546.     $$if Worksheet.Document
  547.     DrawGrowIcon(theWS->theWindow);                /* Draw the Grow box */
  548.  
  549.     $$endif Worksheet.Document
  550.     DrawControls(theWS->theWindow);    
  551.  
  552.     SetPort(SavePort);                            /* Restore the old port */
  553.     }
  554. }
  555.  
  556. /* ======================================================= */
  557.  
  558. /* Routine: Open */
  559. /* Purpose: Open our window */
  560.  
  561. void CmmW$Worksheet.name$::Open()
  562. {
  563. $$if Worksheet.Document
  564. Rect        temp2Rect;                                /* Used for scrollbar placement */
  565. short        ScrollAreaHeight;                        /* Used for scrollbar placement */
  566. short        ScrollAreaWidth;                        /* Used for scrollbar placement */
  567. $$endif
  568. WindowPtr    BehindWindow;                            /* Used for window placement */
  569. long        theLong;                                /* Used for icons and hotspots definition */
  570. $$if Worksheet.SavePosition
  571. Point        DefaultPosition;                        /* Used for window placement */
  572. Point        theWantedPosition;
  573. $$endif
  574. $Worksheet.name$PRec        theWS;
  575.  
  576.  
  577. if ((this->ListRecPtr == nil) || (this->MultipleInstances))
  578.     {
  579.     theWS = ($Worksheet.name$PRec)NewPtrClear(sizeof($Worksheet.name$Rec));
  580.     this->RecPtr = theWS;
  581.     theWS->Next = this->ListRecPtr;
  582.     this->ListRecPtr = theWS;
  583.     
  584.     this->InitRecord(theWS);
  585.  
  586.     BehindWindow = Mk_BehindWindow($Worksheet.Layer$);    /* Get which window to place below */
  587.  
  588.     if (Has.ColorQD)                                /* See if color QuickDraw is around */
  589.         theWS->theWindow = GetNewCWindow(ResW_$Worksheet.name$,nil,BehindWindow);/* Get the COLOR window from the resource file */
  590.     else
  591.         theWS->theWindow = GetNewWindow(ResW_$Worksheet.name$,nil,BehindWindow);/* Get the window from the resource file */
  592.     Mk_RegisterWindow(theWS->theWindow,$Worksheet.Layer$);    /* Register the window with the layers */
  593.     SetPort(theWS->theWindow);                        /* Prepare to write into our window */
  594.  
  595.     $$if Worksheet.Center
  596.     tempRect = theWS->theWindow->portRect;            /* Get the windows position and size */
  597.     $$if Worksheet.CenterHorz
  598.     tempRect.left = ((screenRect.bounds.right -screenRect.bounds.left) - (tempRect.right - tempRect.left)) / 2;    /* Center Horz */
  599.     $$endif Worksheet.CenterHorz
  600.     $$if Worksheet.CenterVert
  601.     tempRect.top = ((screenRect.bounds.bottom - screenRect.bounds.top) - (tempRect.bottom - tempRect.top)) / 3;    /* 1/3 vert */
  602.     if (tempRect.top < 40)                            /* Keep below the menu bar */
  603.         tempRect.top = 40;
  604.     $$endif Worksheet.CenterVert
  605.     MoveWindow(theWS->theWindow,tempRect.left,tempRect.top,true);
  606.     $$endif
  607.  
  608. $$Loop Control.type = Button
  609.     /* Make a button */
  610.     theWS->Ctrl_$Control.name$ = MakeNormalControl(theWS->theWindow,ResC_$Control.name$,theWS->Enable_$Control.name$,0);
  611.  
  612. $$EndLoop Control.type = Button
  613. $$Loop Control.type = Checkbox
  614.     /* Make a checkbox */
  615.     theWS->Ctrl_$Control.name$ = MakeNormalControl(theWS->theWindow,ResC_$Control.name$,
  616.         theWS->Enable_$Control.name$,theWS->Value_$Control.name$);
  617.  
  618. $$EndLoop Control.type = Checkbox
  619. $$Loop Control.type = Radio
  620.     /* Make a Radio */
  621.     theWS->Ctrl_$Control.name$ = MakeNormalControl(theWS->theWindow,ResC_$Control.name$,
  622.         theWS->Enable_$Control.name$,theWS->Value_$Control.name$);
  623.  
  624. $$EndLoop Control.type = Radio
  625. $$Loop Control.type = HotRect
  626.     /* Make a HotSpot/rect */
  627.     theWS->Ctrl_$Control.name$ = MakeHotSpot(theWS->theWindow,ResC_$Control.name$,
  628.         $Control.MakeHotSpot$,$Control.LineWidth$,$Control.ShadowWidth$,sResC_$Control.name$,theWS->Enable_$Control.name$);
  629.     theWS->Rect_$Control.name$ = (*(theWS->Ctrl_$Control.name$))->contrlRect;    /* Get the position */
  630.  
  631. $$EndLoop Control.type = HotRect
  632. $$Loop Control.type = List
  633.     /* Make a List */
  634.     Make_A_List(&theWS->List_$Control.name$,&theWS->ListRect_$Control.name$,
  635.         theWS->theWindow,ResC_$Control.name$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$,false);
  636.     
  637. $$EndLoop Control.type = List
  638. $$Loop Control.type = EditText
  639.     /* Open a TE box, $Control.FullName$ */
  640.     Make_TE_Area(&theWS->TE_$Control.name$,&theWS->TERect_$Control.name$,$Control.TextSize$,$Control.TextFont$,sResC_$Control.name$);/* Make the TE */
  641.     TESetText(&theWS->TEStr_$Control.name$[1],theWS->TEStr_$Control.name$[0],theWS->TE_$Control.name$);
  642.  
  643. $$EndLoop Control.type = EditText
  644. $$Loop Control.type = Icon
  645.     $$if Control.NonGraphic
  646.     /* Make an icon button */
  647.     theWS->Ctrl_$Control.name$ = MakeIconSicn(theWS->theWindow,ResC_$Control.name$,
  648.         theWS->Enable_$Control.name$,ResC_N_$Control.name$,ResC_H_$Control.name$);
  649.  
  650.     $$endif Control.NonGraphic
  651. $$EndLoop Control.type = Icon
  652. $$Loop Control.type = Sicn
  653.     $$if Control.NonGraphic
  654.     /* Make an sicn button */
  655.     theWS->Ctrl_$Control.name$ = MakeIconSicn(theWS->theWindow,ResC_$Control.name$,
  656.         theWS->Enable_$Control.name$,ResC_N_$Control.name$,ResC_H_$Control.name$);
  657.  
  658.     $$endif Control.NonGraphic
  659. $$EndLoop Control.type = Sicn
  660. $$Loop Control.type = Picture
  661.     $$if Control.NonGraphic
  662.     /* Make an picture button */
  663.     theWS->Ctrl_$Control.name$ = MakePlugin(theWS->theWindow,ResC_$Control.name$,
  664.     $$if Control.ClipPicture
  665.         theWS->Enable_$Control.name$,ResC_N_$Control.name$,1,0,0);    /* Clipped */
  666.     $$endif Control.ClipPicture
  667.     $$if Control.ResizePicture
  668.         theWS->Enable_$Control.name$,ResC_N_$Control.name$,0,0,0);    /* Resized */
  669.     $$endif Control.ResizePicture
  670.  
  671.     $$endif Control.NonGraphic
  672. $$EndLoop Control.type = Picture
  673. $$Loop Control.type = ScrollBar
  674.     /* Make a scroll bar */
  675.     theWS->Ctrl_$Control.name$ = GetNewControl(ResC_$Control.name$,theWS->theWindow);/* Make a new scrollbar */
  676.     if (theWS->Enable_$Control.name$)
  677.         HiliteControl(theWS->Ctrl_$Control.name$,0);            /* Enable the ScrollBar */
  678.     else
  679.         HiliteControl(theWS->Ctrl_$Control.name$,255);            /* Disable the ScrollBar */
  680.     MakeMinMaxValue(theWS->Ctrl_$Control.name$,$Control.MinScroll$,$Control.MaxScroll$,theWS->Value_$Control.name$);
  681.  
  682. $$EndLoop Control.type = ScrollBar
  683. $$Loop Control.type = Popup
  684.     /* Make a Popup Menu */
  685.     theWS->Ctrl_$Control.name$ = MakePopupMenu(theWS->theWindow,ResC_$Control.name$,
  686.         theWS->Enable_$Control.name$,mResC_$Control.name$,theWS->Value_$Control.name$);
  687.  
  688. $$EndLoop Control.type = Popup
  689. $$Loop Control.type = Palette
  690.     /* Make a Palette */
  691.     theWS->Ctrl_$Control.name$ = MakePalette(theWS->theWindow,ResC_$Control.name$,
  692.         theWS->Enable_$Control.name$,$Control.NumRows$,$Control.NumColumns$,ResC_N_$Control.name$,$Control.HMethod$);
  693.  
  694. $$EndLoop Control.type = Palette
  695. $$Loop Control.type = UButton
  696.     /* Make a plugin button */
  697.     theWS->Ctrl_$Control.name$ = MakePlugin(theWS->theWindow,ResC_$Control.name$,
  698.         theWS->Enable_$Control.name$,ResC_N_$Control.name$,ResC_H_$Control.name$,0,0);
  699.  
  700. $$EndLoop Control.type = UButton
  701. $$Loop Control.type = UToggle
  702.     /* Make a plugin toggle, $Control.FullName$ */
  703.     theWS->Ctrl_$Control.name$ = MakePlugin(theWS->theWindow,ResC_$Control.name$,
  704.         theWS->Enable_$Control.name$,ResC_N_$Control.name$,ResC_H_$Control.name$,0,theWS->Value_$Control.name$);
  705.  
  706. $$EndLoop Control.type = UToggle
  707. $$Loop Control.type = UGauge
  708.     /* Make a plugin gauge, $Control.FullName$ */
  709.     theWS->Ctrl_$Control.name$ = MakePlugin(theWS->theWindow,ResC_$Control.name$,
  710.         theWS->Enable_$Control.name$,ResC_N_$Control.name$,ResC_H_$Control.name$,0,theWS->Value_$Control.name$);
  711.     MakeMinMaxValue(theWS->Ctrl_$Control.name$,$Control.MinScroll$,$Control.MaxScroll$,theWS->Value_$Control.name$);
  712.  
  713. $$EndLoop Control.type = UGauge
  714.  
  715. $$if Worksheet.Document
  716. $$if Worksheet.ScrollHorz
  717.     SetRect(&tempRect,1,1,1,1);
  718.     theWS->ScrollHHandle = NewControl(theWS->theWindow,&tempRect,"\pHorz Scroll",true,1,1,100,scrollBarProc,12345L);
  719.     this->Resized(&tempRect,theWS->theWindow);
  720.     HiliteControl(theWS->ScrollHHandle,255);
  721. $$endif
  722. $$if Worksheet.ScrollVert
  723.     SetRect(&tempRect,1,1,1,1);
  724.     theWS->ScrollVHandle = NewControl(theWS->theWindow,&tempRect,"\pVert Scroll",true,1,1,100,scrollBarProc,12346L);
  725.     this->Resized(&tempRect,theWS->theWindow);
  726.     HiliteControl(theWS->ScrollVHandle,255);
  727. $$endif
  728. $$endif Worksheet.Document
  729.  
  730.     $$if Worksheet.SavePosition
  731.     SetPort(theWS->theWindow);                        /* Select our window */
  732.     DefaultPosition.h = 0;                            /* Reset Horz position */
  733.     DefaultPosition.v = 0;                            /* Reset Vert position */
  734.     LocalToGlobal(&DefaultPosition);                /* Get global location */
  735.     theWantedPosition.h = theWindowLocRec.Loc_$Worksheet.name$.left;
  736.     theWantedPosition.v = theWindowLocRec.Loc_$Worksheet.name$.top;
  737.     PositionWindow(theWS->theWindow,theWantedPosition,DefaultPosition);
  738.     if (theWindowLocRec.Loc_$Worksheet.name$.left != theWindowLocRec.Loc_$Worksheet.name$.right)
  739.         {
  740.         SizeWindow(theWS->theWindow,theWindowLocRec.Loc_$Worksheet.name$.right - theWindowLocRec.Loc_$Worksheet.name$.left,
  741.             theWindowLocRec.Loc_$Worksheet.name$.bottom - theWindowLocRec.Loc_$Worksheet.name$.top,true);
  742.         SetRect(&tempRect,1,1,1,1);
  743.         this->Resized(&tempRect,theWS->theWindow);
  744.         }
  745.  
  746.     $$endif Worksheet.SavePosition
  747.  
  748.     this->OpenExtras((Ptr)theWS);                    /* HOOK */
  749.  
  750.     ShowWindow(theWS->theWindow);                    /* Show the window now */
  751.  
  752.     $$Link    Worksheet.Open
  753.     }
  754. else
  755.     theWS = this->ListRecPtr;
  756.  
  757. Mk_HiliteWindow(theWS->theWindow);                    /* Already open, so show it */
  758. }
  759.  
  760. /* ======================================================= */
  761.  
  762. /* Routine: Activate */
  763. /* Purpose: We activated or deactivated */
  764.  
  765. void CmmW$Worksheet.name$::Activate(WindowPtr whichWindow,Boolean Do_An_Activate)
  766. {
  767. WindowPtr    SavePort;                                /* Place to save the last port */
  768. $Worksheet.name$PRec        theWS;
  769.  
  770.  
  771. LocateInstance(whichWindow);
  772.  
  773. if (this->RecPtr != nil)                            /* Only do if the window is us */
  774.     {
  775.     theWS = this->RecPtr;
  776.  
  777.     GetPort(&SavePort);                                /* Save the current port */
  778.     SetPort(whichWindow);                            /* Set the port to my window */
  779.  
  780.     $$if Worksheet.Document
  781.     DrawGrowIcon(whichWindow);                        /* Draw the Grow box */
  782.  
  783.     $$endif Worksheet.Document
  784.     if (!Do_An_Activate)                            /* Handle the deactivate */
  785.         {
  786.         if (theInput != nil)                        /* See if there is already a TE area */
  787.             TEDeactivate(theInput);                    /* Yes, so turn it off */
  788.         theInput = nil;                                /* Deactivate the TE area */
  789. $$if Worksheet.Document
  790. $$if Worksheet.ScrollHorz
  791.         HiliteControl(theWS->ScrollHHandle,255);
  792. $$endif
  793. $$if Worksheet.ScrollVert
  794.         HiliteControl(theWS->ScrollVHandle,255);
  795. $$endif
  796. $$endif Worksheet.Document
  797.         $$Link    Worksheet.Deactivate
  798.         }
  799.     else
  800.         {
  801. $$if Worksheet.Document
  802. $$if Worksheet.ScrollHorz
  803.         HiliteControl(theWS->ScrollHHandle,0);
  804. $$endif
  805. $$if Worksheet.ScrollVert
  806.         HiliteControl(theWS->ScrollVHandle,0);
  807. $$endif
  808. $$endif Worksheet.Document
  809.         $$Link    Worksheet.Activate
  810.         }
  811.  
  812.     this->ActivateExtras(Do_An_Activate,(Ptr)theWS);    /* HOOK */
  813.     
  814.     SetPort(SavePort);                                /* Restore the old port */
  815.     }
  816. }
  817.  
  818. /* ======================================================= */
  819.  
  820. /* Routine: Do_A_Button */
  821. /* Purpose: Handle a button pressed */
  822.  
  823. void CmmW$Worksheet.name$::HandleButton(WindowPtr whichWindow,ControlHandle theControl)    /* Handle a button being pressed */
  824. {
  825. long        RefCon;                                    /* RefCon for controls */
  826. short        UnHiliteValue;                            /* For unhilite */
  827. short        theSelection;                            /* For palettes and popups */
  828. $Worksheet.name$PRec        theWS;
  829.  
  830.  
  831. LocateInstance(whichWindow);
  832.  
  833. if (this->RecPtr != nil)                            /* Only do if the window is us */
  834.     {
  835.     theWS = this->RecPtr;
  836.  
  837.     HiliteControl(theControl,10);                        /* Darken the button */
  838.     UnHiliteValue = 0;                                    /* To lighten the button */
  839.     RefCon = GetCRefCon(theControl);                    /* get control refcon */
  840.     
  841.     switch (RefCon)                                        /* Select correct button */
  842.         {
  843.         $$Loop Control.type = Button
  844.         $$if Control.HasLinks
  845.         case ResC_$Control.name$:                    /* Button, $Control.FullName$ */
  846.             $$Link    Control.Select
  847.             break;
  848.         $$endif
  849.         $$EndLoop Control.type = Button
  850.         $$Loop Control.type = HotRect
  851.         $$if Control.HasLinks
  852.         $$if Control.HotSpot
  853.         case ResC_$Control.name$:                    /* HotSpot, $Control.FullName$ */
  854.             $$Link    Control.Select
  855.             break;
  856.         $$endif Control.HotSpot
  857.         $$endif
  858.         $$EndLoop Control.type = HotRect
  859.         $$Loop Control.type = Icon
  860.         $$if Control.HasLinks
  861.         $$if Control.NonGraphic
  862.         case ResC_$Control.name$:                    /* Icon, $Control.FullName$ */
  863.             $$Link    Control.Select
  864.             break;
  865.         $$endif Control.NonGraphic
  866.         $$endif
  867.         $$EndLoop Control.type = Icon
  868.         $$Loop Control.type = Sicn
  869.         $$if Control.HasLinks
  870.         $$if Control.NonGraphic
  871.         case ResC_$Control.name$:                    /* Sicn, $Control.FullName$ */
  872.             $$Link    Control.Select
  873.             break;
  874.         $$endif Control.NonGraphic
  875.         $$endif
  876.         $$EndLoop Control.type = Sicn
  877.         $$Loop Control.type = Picture
  878.         $$if Control.HasLinks
  879.         $$if Control.NonGraphic
  880.         case ResC_$Control.name$:                    /* Picture, $Control.FullName$ */
  881.             $$Link    Control.Select
  882.             break;
  883.         $$endif Control.NonGraphic
  884.         $$endif
  885.         $$EndLoop Control.type = Picture
  886.         $$Loop Control.type = UButton
  887.         $$if Control.HasLinks
  888.         case ResC_$Control.name$:                    /* Plugin Button, $Control.FullName$ */
  889.             $$Link    Control.Select
  890.             break;
  891.         $$endif
  892.         $$EndLoop Control.type = UButton
  893.         $$Loop Control.type = Popup
  894.         case ResC_$Control.name$:                    /* PopUp, $Control.FullName$ */
  895.             theSelection = GetCtlValue(theWS->Ctrl_$Control.name$);    /* Get the Popup selection value */
  896.             switch (theSelection)                    /* Select correct item */
  897.                 {
  898.                 $$Loop PopupItems
  899.                 case $Control.PopupID$:                /* $Control.PopupID$, for $Control.PopupName$ */
  900.                     break;
  901.                 $$EndLoop PopupItems
  902.     
  903.                 default:                            /* allow other buttons, trap for debug */
  904.                     break;                            /* end of otherwise */
  905.                 }                                    /* end of switch */
  906.             break;
  907.         $$EndLoop Control.type = Popup
  908.         $$Loop Control.type = Palette
  909.         case ResC_$Control.name$:                /* Tool palette, $Control.FullName$ */
  910.             theWS->Value_$Control.name$ = GetCtlValue(theWS->Ctrl_$Control.name$);/* Get the palette value, 0xrrcc, rr is row, cc is column */
  911.             break;
  912.         $$EndLoop Control.type = Palette
  913.     
  914.         default:                                    /* allow other buttons, trap for debug */
  915.             break;                                /* end of otherwise */
  916.         }                                            /* end of switch */
  917.  
  918.     this->HandleExtraButtons((Ptr)theWS,theControl,&UnHiliteValue);
  919.     
  920.     HiliteControl(theControl,UnHiliteValue);            /* Lighten the button */
  921.     }
  922.  
  923. }                                                    /* End of Handle a button being pressed */
  924.  
  925. $$if Worksheet.CheckboxesOrRadios
  926. /* ======================================================= */
  927.  
  928. void CmmW$Worksheet.name$::HandleCheckbox(WindowPtr whichWindow,ControlHandle theControl)/* Handle a checkbox being pressed */
  929. {
  930. long    RefCon;                                        /* RefCon for controls */
  931. short    theValue;                                    /* Current value of a control */
  932. $Worksheet.name$PRec        theWS;
  933.  
  934.  
  935. LocateInstance(whichWindow);
  936.  
  937. if (this->RecPtr != nil)                            /* Only do if the window is us */
  938.     {
  939.     theWS = this->RecPtr;
  940.  
  941.     RefCon = GetCRefCon(theControl);                    /* get control refcon */
  942.     theValue = GetCtlValue(theControl);                    /* Get current value */
  943.     theValue = (theValue + 1) & 1;                        /* Change value from 1 to 0 or from 0 to 1 */
  944.     
  945.     switch (RefCon)                                        /* Select correct control */
  946.         {
  947.         $$Loop Control.type = Checkbox
  948.         case ResC_$Control.name$:                        /* Checkbox, $Control.FullName$  */
  949.             SetCtlValue(theControl, theValue);            /* Set checkbox to new value  */
  950.             theWS->Value_$Control.name$ = theValue;
  951.             $$if Control.HasLinks
  952.             if (theValue == 0)
  953.                 {
  954.                 $$Link    Control.Deselect
  955.                 }
  956.             else
  957.                 {
  958.                 $$Link    Control.Select
  959.                 }
  960.             $$endif
  961.             break;
  962.         $$EndLoop Control.type = Checkbox
  963.         $$Loop Control.type = UToggle
  964.         case ResC_$Control.name$:                        /* Plugin Toggle, $Control.FullName$  */
  965.             SetCtlValue(theControl, theValue);            /* Set checkbox to new value  */
  966.             theWS->Value_$Control.name$ = theValue;
  967.             $$if Control.HasLinks
  968.             if (theValue == 0)
  969.                 {
  970.                 $$Link    Control.Deselect
  971.                 }
  972.             else
  973.                 {
  974.                 $$Link    Control.Select
  975.                 }
  976.             $$endif
  977.             break;
  978.         $$EndLoop Control.type = UToggle
  979.         $$Loop Control.type = Radio
  980.         case ResC_$Control.name$:                        /* Radio, $Control.FullName$  */
  981.             theWS->Value_$Control.name$ = 1;            /* Set the Radio value */
  982.             SetCtlValue(theControl,1);                    /* Select this Radio  */
  983.     
  984.             /* Clear other Radio values in this group */
  985.             $$Loop RadioGroup
  986.             SetCtlValue(theWS->Ctrl_$Control.name$,0);
  987.             theWS->Value_$Control.name$ = 0;            /* Clear other radio */
  988.             $$EndLoop RadioGroup
  989.             $$Link    Control.Select
  990.             break;
  991.         $$EndLoop Control.type = Radio
  992.     
  993.         default:                                    /* allow other checkboxes and radios, trap for debug */
  994.             break;                                    /* end of otherwise */
  995.         }                                            /* end of case */
  996.  
  997.     this->HandleExtraCheckboxes((Ptr)theWS,theControl);
  998.     }
  999.  
  1000. }
  1001.  
  1002. $$endif
  1003. /* ======================================================= */
  1004.  
  1005. /* Routine: HandleEvent */
  1006. /* Purpose: Handle action to our window, like controls */
  1007.  
  1008. void CmmW$Worksheet.name$::HandleEvent(EventRecord *myEvent)
  1009. {
  1010. short            code;                            /* Location of event in window or controls */
  1011. WindowPtr        whichWindow;                    /* Window pointer where event happened */
  1012. Point            myPt;                            /* Point where event happened */
  1013. ControlHandle    theControl;                        /* Handle for a control */
  1014. $Worksheet.name$PRec        theWS;
  1015.  
  1016.  
  1017. code = FindWindow(myEvent->where,&whichWindow);    /* Get where in window and which window */
  1018.  
  1019. LocateInstance(whichWindow);
  1020.  
  1021. if (this->RecPtr != nil)                        /* Only do if the window is us */
  1022.     {
  1023.     theWS = this->RecPtr;
  1024.  
  1025.     $$if HasEditLists
  1026.     if (myEvent->what == mouseDown)
  1027.         {
  1028.         myPt = myEvent->where;                    /* Get mouse position */
  1029.         GlobalToLocal(&myPt);                    /* Make it relative */
  1030.  
  1031.         $$Loop Control.type = EditText
  1032.         if (PtInRect(myPt,&theWS->TERect_$Control.name$))    /* Check for pressed in the TE  Edit Text  */
  1033.             {
  1034.             Activate_TE_Area(false,myPt,theWS->TE_$Control.name$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$);
  1035.             whichWindow = NIL;                    /* Do not let anyone else handle it */
  1036.             }
  1037.  
  1038.         $$EndLoop Control.type = EditText
  1039.         $$Loop Control.type = List
  1040.         if (PtInRect(myPt,&theWS->ListRect_$Control.name$))
  1041.             {
  1042.             ClickInTheList(myPt,myEvent->modifiers,theWS->List_$Control.name$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$,false);
  1043.             whichWindow = NIL;                    /* Do not let anyone else handle it */
  1044.             }
  1045.  
  1046.         $$EndLoop Control.type = List
  1047.         }
  1048.  
  1049.     $$endif HasEditLists
  1050.     if ((theWS->theWindow == whichWindow) && (code == inContent))    /* for our window */
  1051.         {
  1052.         myPt = myEvent->where;                    /* Get mouse position */
  1053.         GlobalToLocal(&myPt);                    /* Make it relative */
  1054.  
  1055.         code = FindControl(myPt,whichWindow,&theControl);    /* Get type of control */
  1056.  
  1057.         $$if Worksheet.Scrollbars
  1058.         if ((code == inUpButton) || (code == inDownButton) || (code == inThumb) ||  (code == inPageDown) || (code == inPageUp))
  1059.             this->HandleScrollBar(code,theControl,myPt);    /* Do scrollbars */
  1060.         else
  1061.         $$endif
  1062.         if (code != 0)                                /* Check type of control */
  1063.             code = TrackControl(theControl,myPt,(ControlActionUPP)-1);/* Track the control */
  1064.         if (code == inButton)
  1065.             this->HandleButton(whichWindow,theControl);            /* Do buttons */
  1066.         $$if Worksheet.CheckboxesOrRadios
  1067.         else if (code == inCheckBox)
  1068.             this->HandleCheckbox(whichWindow,theControl);        /* Do checkboxes and radios */
  1069.         $$endif
  1070.  
  1071.         }
  1072.     }
  1073. }
  1074.  
  1075. /* ======================================================= */
  1076. /* ======================================================= */
  1077. $$CloseFile
  1078. $$EndLoop
  1079.  
  1080.  
  1081.